<template>
  <main-nav-bar>
    <template v-slot:center-name>
      <div>我的发布</div>
    </template>
    <template v-slot:home-nav-back>
      <div><i class="iconfont icon-jiantou2"></i></div>
    </template>
  </main-nav-bar>
  <scroller
      class="home-scroller"
      ref="scroller"
      :probe-type="3"
      @scroll="getPostion"
      @pullingUp="pullingUp">
    <review-item
      :reviewMsgList="item"
      v-for="item in reviewList.rows"
      :key="item.id"
      :isAddEvent="true"
      :canDelete="true"
    />
  </scroller>

  <div class="delete_bgc" @click="changeState" v-show="$store.state.showDelete">
    <div class="bgc"></div>
    <div class="delete" @click="toDelete">删除</div>
  </div>
</template>

<script>
import { onMounted, reactive, ref } from "vue";
import { useRouter } from "vue-router";
import {useStore} from "vuex"
import MainNavBar from "../../components/content/mainnavbar/MainNavBar.vue";
import reviewItem from "/@/components/commont/reviewItem/reviewItem.vue";
import scroller from "../../components/commont/scroller/Scroller.vue";
import { request } from "/@/network/request.js";
import {Toast}from "vant"
export default {
  components: {
    MainNavBar,
    reviewItem,
    scroller,
  },
  setup() {
    const router = useRouter();
    const store = useStore();
    const flage = ref(false);
    const page = ref(1);
    const scroller = ref(null);
    const reviewList = reactive({
      rows: [],
    });
    const toDelete = async () => {
      const club_id = store.state.deleteId
       try {
         const res = await request({
          url:"v1.ucenter/del_club",
          data:{
            user_id:sessionStorage.getItem("user_id"),
            club_id
          }
        })
        if(res.code==200){
          Toast(res.msg);
          getMyPublish(true)
        }
       } catch (error) {
         
       }
      
    };
    const getMyPublish = async (first = false) => {
      if(first)page.value = 1;
      const res = await request({
        url: "v1.ucenter/club_list",
        data: {
          user_id: sessionStorage.getItem("user_id"),
          page: page.value,
        },
      });
      if(first){
       reviewList.rows = res.data.rows;
       page.value += 1;
       return
      }
      if (res.data.rows.length != 0) {
        reviewList.rows.push(...res.data.rows);
        page.value += 1;
      } else {
          Toast({
          message:"没有更多了",
        });
      }
      scroller.value.finishPullUp();
    };
    const getPostion = (position) => {
      //   console.log(scroller.value.refresh);
      //   position.y
    };
    const pullingUp = ()=>{
        getMyPublish()
    }
    const changeState = ()=>{
        store.commit("changeDeleteFalse")
    }
    onMounted(() => {
      getMyPublish(true);
    });
    return {
      flage,
      toDelete,
      reviewList,
      pullingUp,
      getPostion,
      scroller,
      changeState
    };
  },
};
</script>

<style  scoped>
.home-scroller {
  /* padding-top: 24px; */
  height: calc(100vh - 14vw);
  margin-top:17.933vw;

  /* padding-top:29.933vw; */
  /* overflow: hidden; */
}
.bgc {
  width: 100%;
  height: 100%;
  position: fixed;
  background-color: #7e7e7e;
  opacity: 0.8;
  z-index: 999;
}
.delete {
  width: 88.267vw;
  height: 13.333vw;
  font-size: 4.8vw;
  background-color: #fff;
  color: #620000;
  text-align: center;
  line-height: 13.333vw;
  border-radius: 2.667vw;
  position: fixed;
  bottom: 14.933vw;
  left: 5.867vw;
  z-index: 99999999999999;
  transform: translateZ(2px);
}
.delete_bgc{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  height: 100vh;
  width: 100vw;
  z-index: 9999999;
  transform: translateZ(2px);
}
.delete_bgc .bgc{
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  height: 100vh;
  z-index: 99999999999999;
  transform: translateZ(2px);
}
</style>